package com.ruoyi.web.controller.file;


import com.ruoyi.common.exception.IcanResult;
import com.ruoyi.system.service.impl.CommonService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/tar/wjsc")
@Api(tags = "文件上传")
public class UploadController {

@Autowired
CommonService commonService;



    /**
     * 大文件分包上传
     *
     * @data 2021/12/6 14:14
     */
    @PostMapping("/subpackageUploadFile")
    @ApiOperation(value = "分包上传文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "identifier", value = "文件标识"),
            @ApiImplicitParam(name = "totalChunks", value = "总包数"),
            @ApiImplicitParam(name = "chunkNumber", value = "当前上传包"),
            @ApiImplicitParam(name = "file", value = "文件"),
    })
    public IcanResult subpackageUploadFile(@RequestParam("file") MultipartFile file,
                                           @RequestParam("totalChunks")String totalChunks,
                                           @RequestParam("chunkNumber")String chunkNumber,
                                           @RequestParam("identifier")String identifier) throws IOException {

        log.info("----------------------" + file.getOriginalFilename() + "---文件上传中...，总包数：" + totalChunks + "，当前上传包：" + chunkNumber);

        return commonService.subpackageUploadFile(file, totalChunks, chunkNumber, identifier);

    }


    /**
     * 合并分包上传的文件
     *
     * @data 2021/12/20 17:34
     */
    @RequestMapping("/subpackageUploadMerge")
    @ApiOperation(value = "合并分包上传的文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fileName", value = "文件名称"),
            @ApiImplicitParam(name = "identifier", value = "文件标识"),
            @ApiImplicitParam(name = "dataType", value = "数据类型：1 目标整编 2部署体系 3判读样片"),
            @ApiImplicitParam(name = "fileType", value = "文件类型：1 图片 2 视频 3 影像 4 音频 5 矢量 6 地名数据 7 文档 8 zip 9 临时文件"),
    })
    public IcanResult subpackageUploadMerge(String fileName,
                                            String identifier,
                                            Integer dataType,
                                            Integer fileType) {
        log.info("----------------------" + fileName + "---文件分包上传结束，合并中...");
        return commonService.subpackageUploadMerge(fileName, identifier, dataType, fileType);
    }




    /**
     * 单文件上传
     *
     * @data 2021/12/20 17:34
     */
//    @ApiOperation(value = "单文件上传",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
//    @PostMapping (value = "/danwjsc",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
//    public IcanResult danwjsc( @RequestPart("file")  MultipartFile file) throws Exception{
//
//        IcanResult icanResult =  wjxxService.danwjsc(file);
//
//        return icanResult;
//    }




}
